var FYR = {
  subscribe: function(url) {
    var ps = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
    
    var urlPattern = ps.getCharPref("fyr.urlpattern");
    var t = urlPattern.replace(/@URL@/, url);

    if (t.match(/^http/i)) {
      getBrowser().addTab(t);
    } else {
      document.getElementById("content").loadURI(t)
    }
  },
  contextMenuShowing: function() {
    var thisLink = document.getElementById('fyr-subscribe-menu-item');
    var thisPage = document.getElementById('fyr-subscribe-this-page-menu-item');
    if (gContextMenu.onLink) {
      var url = gContextMenu.linkURL;
      if (url.match(/^http/i)) {
	thisLink.hidden=false;
	thisPage.hidden=true;
      } else {
	thisLink.hidden=true;
	thisPage.hidden=false;
      }
    } else {
      thisLink.hidden=true;	
      thisPage.hidden=false;
    }
  }
};
  
function fyr_init() {
  FeedHandler.addLiveBookmark = FYR.subscribe;
  var cm = document.getElementById('contentAreaContextMenu');
  cm.addEventListener('popupshowing', FYR.contextMenuShowing, false);
}

window.addEventListener('load', fyr_init, false);
